package com.fantasy.dao.impl;

import com.fantasy.dao.BaseDao;
import com.fantasy.dao.OrderDao;
import com.fantasy.entity.Admin;
import com.fantasy.entity.Order;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int insert(Order order) {
        String sql="INSERT INTO `order` (`id`,`userId`,`money`,`orderDate`,`state`)VALUES(?,?,?,?,?)";
        return super.update(sql,order.getId(),order.getUserId(),order.getMoney(),order.getOrderDate(),order.getState());
    }

    @Override
    public int update(Order order) {
        String sql="UPDATE  `order` SET `userId`=?,`money`=?,`orderDate`=?,`state`=? where `id`=?";
        return super.update(sql,order.getUserId(),order.getMoney(),order.getOrderDate(),order.getState(),order.getId());
    }

    @Override
    public int delete(int id) {
        String sql="DELETE FROM `order` WHERE `id`=?";
        return super.update(sql,id);
    }

    @Override
    public Order queryByUserId(int userid) {
        String sql="SELECT FROM `order` WHERE `userId`=? ";
        return super.queryForOne(Order.class,sql,userid);
    }

    @Override
    public List<Order> queryAll() {
        String sql="SELECT * FROM `order`";
        return super.queryForList(Order.class,sql);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql = "SELECT COUNT(1) FROM `order`";
        Number count = (Number) super.queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public List<Order> queryForPageItems(int begin, int pageSize) {
        String sql = "SELECT * FROM `order` LIMIT ?, ?";
        return super.queryForList(Order.class,sql,begin,pageSize);
    }
}
